<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户登录注册及图书查询</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f2f2f2;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
        }
        .container {
            background-color: #fff;
            padding: 20px;
            border-radius: 10px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            width: 300px;
            display: none; /* 默认隐藏，除非显示时才展示 */
        }
        .container.active {
            display: block; /* 激活状态显示 */
        }
        .container h2 {
            text-align: center;
            margin-bottom: 20px;
        }
        .container input[type="text"], .container input[type="password"], .container input[type="email"] {
            width: 100%;
            padding: 10px;
            margin: 10px 0;
            border: 1px solid #ccc;
            border-radius: 5px;
        }
        .container input[type="submit"] {
            width: 100%;
            padding: 10px;
            border: none;
            border-radius: 5px;
            background-color: #4CAF50;
            color: white;
            font-size: 16px;
        }
        .container input[type="submit"]:hover {
            background-color: #45a049;
        }
        .container .toggle-link {
            text-align: center;
            margin-top: 10px;
            color: #4CAF50;
            cursor: pointer;
        }
    </style>
</head>
<body>
<div class="container active" id="loginContainer">
    <h2>登录</h2>
    <form action="/login" method="post">
        <label for="loginUsername">用户名：</label>
        <input type="text" id="loginUsername" name="username" required>

        <label for="loginPassword">密码：</label>
        <input type="password" id="loginPassword" name="password" required>

        <input type="submit" value="登录">
    </form>
    <div class="toggle-link" onclick="toggleForm('registerContainer')">没有账号？注册</div>
    <div class="toggle-link" onclick="toggleForm('searchContainer')">直接查询图书</div>
</div>

<div class="container" id="registerContainer">
    <h2>注册</h2>
    <form action="/register" method="post">
        <label for="registerUsername">用户名：</label>
        <input type="text" id="registerUsername" name="username" required>

        <label for="registerEmail">电子邮件：</label>
        <input type="email" id="registerEmail" name="email" required>

        <label for="registerPassword">密码：</label>
        <input type="password" id="registerPassword" name="password" required>

        <input type="submit" value="注册">
    </form>
    <div class="toggle-link" onclick="toggleForm('loginContainer')">已有账号？登录</div>
</div>

<div class="container" id="searchContainer">
    <h2>图书查询</h2>
    <form action="/search" method="get">
        <label for="bookName">图书名：</label>
        <input type="text" id="bookName" name="bookName" required>

        <input type="submit" value="查询">
    </form>
    <div class="toggle-link" onclick="toggleForm('loginContainer')">返回登录</div>
</div>

<script>
    function toggleForm(formId) {
        var containers = document.querySelectorAll('.container');
        containers.forEach(function(container) {
            container.classList.remove('active');
        });

        document.getElementById(formId).classList.add('active');
    }
</script>
</body>
</html>
